<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>计算属性与方法的区别</title>
  </head>
  <body>
    <div class="box">
      <form action="">
        <label for="ting">
          用户名 ：
          <input type="text" v-model="datas" />
        </label>
        <button>{{tip}}</button>
      </form>
    </div>
    <script src="../../node_modules/vue/dist/vue.js"></script>
    <script>
      new Vue({
        el: '.box',
        data: {
          datas: '',
          tip: '',
        },
        methods: {
          userChange(newName) {
            setTimeout(() => {
              newName == 'admin'
                ? (this.tip = '用户名重复')
                : (this.tip = '可以设置')
            }, 1000)
          },
        },
        computed: {},
        watch: {
          datas(newDatas) {
            this.tip = '正在验证，请稍等'
            this.userChange(newDatas)
            // setTimeout(() => {
            //   newDatas == 'admin'
            //     ? (this.tip = '用户名重复')
            //     : (this.tip = '可以设置')
            // }, 1000)
          },
        },
      })
    </script>
  </body>
</html>
